package com.jadefashion.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jadefashion.health.entity.QueryPageBean;
import com.jadefashion.mapper.MenuMapper;
import com.jadefashion.pojo.Menu;
import com.jadefashion.service.MenuService;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service(interfaceClass = MenuService.class)
public class MenuServiceImpl implements MenuService {

    @Autowired
    private MenuMapper menuMapper;

    //根据用户姓名查询菜单信息
    @Override
    public List<Menu> findTitle(Map map) {
        //获取用户姓名
        String name = (String) map.get("username");
        return menuMapper.findTitle(name);
    }

    //查询菜单信息
    @Override
    public Map findPage(QueryPageBean queryPageBean) {
        //使用分页插件
        PageHelper.startPage(queryPageBean.getCurrentPage(),queryPageBean.getPageSize());
        //查询菜单数据
        List<Menu> list = menuMapper.findPage(queryPageBean.getQueryString());
        //将数据装入分页插件
        PageInfo pageInfo = new PageInfo(list);

        //创建map集合
        Map map = new HashMap();
        map.put("dataList",pageInfo.getList());
        map.put("total",pageInfo.getTotal());
        return map;
    }

    //添加菜单信息
    @Override
    public void handleAdd(Menu menu) {
        menuMapper.add(menu);
    }

    //修改菜单数据
    @Override
    public void update(Menu menu) {
        menuMapper.update(menu);
    }

    //删除菜单数据
    @Override
    public void delete(Integer id) {
        menuMapper.delete(id);
    }

    //查询所有菜单信息
    @Override
    public List<Menu> findAll() {
        return menuMapper.findAll();
    }

    //根据角色id查询对应的菜单
    @Override
    public List<Menu> findByRolerId(Integer id) {
        return menuMapper.findByRoleId(id);
    }
}
